package com.so.studyonline.service;

import com.so.studyonline.mapper.SoUserMapper;
import com.so.studyonline.model.SoUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SoUserService {
    private SoUserMapper soUserMapper;

    @Autowired
    public void setSoUserMapper(SoUserMapper soUserMapper) {
        this.soUserMapper = soUserMapper;
    }
    /**
     * 单个用户查询，limit 1
     *
     * @param user 查询条件
     * @return 结果
     */
    public SoUser findByUserInfo(SoUser user) {
        try {
            return soUserMapper.findByUserInfo(user);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 新增用户
     *
     * @param user 用户信息
     * @return 结果
     */
    public SoUser addUser(SoUser user) {
        try {
            soUserMapper.addUser(user);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return user;
    }

    /**
     * 更新用户信息
     *
     * @param user 用户信息
     * @return true-更新成功
     */
    public boolean updateOneUser(SoUser user) {
        try {
            soUserMapper.updateOneUser(user);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
